package WordCount;

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

import org.junit.Before;
import org.junit.Test;

public class WordTest {

	
	
	//String file1 = "text1.txt";
	//String file2 = "text2.txt";
	//String file3 = "text3.txt";
	//String file4 = "text4.txt";
/*	Scanner sc =new Scanner(System.in);	
	String file1 = sc.next();
	String file2 = sc.next();
	String file3 = sc.next();
	String file4 = sc.next();
	*/
	
	
	@Before
	public void setUp() throws Exception {
	}
	
	
	
	//统计字符数量测试
	@Test
	public void testGetcharNum() throws IOException {
		OperateFile fd = new OperateFile();
		
	//	System.out.print(file1);
		String str1 = fd.FileToString("test1.txt");//读出文件内容变成字符串
		String str2 = fd.FileToString("test2.txt");
		String str3 = fd.FileToString("test3.txt");
		String str4 = fd.FileToString("test4.txt");
		
		Word wd1 = new Word(str1);
		Word wd2 = new Word(str2);
		Word wd3 = new Word(str3);
		Word wd4 = new Word(str4);
		
		int p1 = wd1.getcharNum();//调用
		int p2 = wd2.getcharNum();
		int p3 = wd3.getcharNum();
		int p4 = wd4.getcharNum();
		
		assertEquals(0, p1);//测试与结果匹配
		assertEquals(37, p2);
		assertEquals(86, p3);
		assertEquals(272, p4);
	}

	@Test
	public void testGetwordNum() throws IOException {//统计单词数量测试
		OperateFile fd = new OperateFile();
		
		String str1 = fd.FileToString("test1.txt");//读出文件内容变成字符串
		String str2 = fd.FileToString("test2.txt");
		String str3 = fd.FileToString("test3.txt");
		String str4 = fd.FileToString("test4.txt");
		
		Word wd1 = new Word(str1);
		Word wd2 = new Word(str2);
		Word wd3 = new Word(str3);
		Word wd4 = new Word(str4);
		
		int p1 = wd1.getwordNum();//调用
		int p2 = wd2.getwordNum();
		int p3 = wd3.getwordNum();
		int p4 = wd4.getwordNum();
		
		assertEquals(0, p1);//测试与结果匹配
		assertEquals(0, p2);
		assertEquals(10, p3);
		assertEquals(35, p4);
	}

	@Test
	public void testGetlineNum() throws IOException {//统计有效行数测试
		OperateFile fd = new OperateFile();
				
		String str1 = fd.FileToString("test1.txt");//读出文件内容变成字符串
		String str2 = fd.FileToString("test2.txt");
		String str3 = fd.FileToString("test3.txt");
		String str4 = fd.FileToString("test4.txt");

		
		Word wd1 = new Word(str1);
		Word wd2 = new Word(str2);
		Word wd3 = new Word(str3);
		Word wd4 = new Word(str4);
		
		int p1 = wd1.getlineNum();//调用
		int p2 = wd2.getlineNum();
		int p3 = wd3.getlineNum();
		int p4 = wd4.getlineNum();
		
		assertEquals(0, p1);//测试与结果匹配
		assertEquals(6, p2);
		assertEquals(4, p3);
		assertEquals(12, p4);
	}

	@Test
	public void testGetwordFreq() throws IOException {//统计词频测试
		OperateFile fd = new OperateFile();
		
		String str1 = fd.FileToString("test1.txt");//读出文件内容变成字符串
		String str2 = fd.FileToString("test2.txt");
		String str5 = fd.FileToString("test5.txt");
	
		
		Word wd1 = new Word(str1);
		Word wd2 = new Word(str2);
		Word wd5 = new Word(str5);

		

		List<Map.Entry<String, Integer>> wordFreq1 = wd1.getwordFreq();
		List<Map.Entry<String, Integer>> wordFreq2 = wd2.getwordFreq();
		List<Map.Entry<String, Integer>> wordFreq5 = wd5.getwordFreq();
		
		Map<String,Integer> w1 = new HashMap<String,Integer>();
		Map<String,Integer> w2 = new HashMap<String,Integer>();
		Map<String,Integer> w3 = new HashMap<String,Integer>();
	//	Map<String,Integer> w4 = new HashMap<String,Integer>();
		w3.put("jiusong", 4);
		w3.put("test111", 1);
	
		List<Map.Entry<String, Integer>> t1 = new ArrayList<Map.Entry<String, Integer>>(w1.entrySet());  
		List<Map.Entry<String, Integer>> t2 = new ArrayList<Map.Entry<String, Integer>>(w2.entrySet());
		List<Map.Entry<String, Integer>> t3 = new ArrayList<Map.Entry<String, Integer>>(w3.entrySet());
		
		assertEquals(t1, wordFreq1);
		assertEquals(t2, wordFreq2);
		assertEquals(t3, wordFreq5);

		
		/*
		jiusong=4
				test111=1*/
	}

}
